package vns.server;

import javax.jdo.PersistenceManager;

import vns.client.service.ObjectTypeLinkService;
import vns.server.domain.ObjectTypeLink;
import vns.shared.ObjectTypeLinkDTO;

import com.google.appengine.api.datastore.Key;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class ObjectTypeLinkServiceImpl extends RemoteServiceServlet 
			implements ObjectTypeLinkService{

	@Override
	public ObjectTypeLinkDTO Create(ObjectTypeLinkDTO opLinkDTO) {
		PersistenceManager pm=PMF.get().getPersistenceManager();
		ObjectTypeLink action=null;
		try{
			action=new ObjectTypeLink(opLinkDTO);
			pm.makePersistent(action);
		}finally{
			pm.close();
		}
		return action.toDTO();
	}

	@Override
	public ObjectTypeLinkDTO load(Key id) {
		PersistenceManager pm=PMF.get().getPersistenceManager();
		ObjectTypeLinkDTO actionDTO=null;
		try{
			ObjectTypeLink action = pm.getObjectById(ObjectTypeLink.class,id);	
			actionDTO=action.toDTO();
		}finally{
			pm.close();
		}
		return actionDTO;
	}

	@Override
	public ObjectTypeLinkDTO Update(ObjectTypeLinkDTO opLinkDTO) {
		PersistenceManager pm=PMF.get().getPersistenceManager();
		ObjectTypeLink action=null;
		try{
			action=pm.getObjectById(ObjectTypeLink.class,opLinkDTO.getId());
			action.updatefromDTO(opLinkDTO);
		}finally{
			pm.close();
		}
		
		return action.toDTO();
	}

	@Override
	public boolean remove(Key id) {
		PersistenceManager pm=PMF.get().getPersistenceManager();
		try{
			ObjectTypeLink action= pm.getObjectById(ObjectTypeLink.class,id);
			if(action!=null){
				pm.deletePersistent(pm.getObjectById(ObjectTypeLink.class,id));
			}
		}finally{
			pm.close();
		}
		return true;
	}

}
